package com.manor.paradise.activity

import android.content.Context
import android.content.Intent
import android.webkit.WebSettings
import com.manor.common.CommonAppConfig.getMetaDataString
import com.manor.common.activity.AbsActivity
import com.manor.paradise.R
import kotlinx.android.synthetic.main.activity_explain.*

/**
 * 说明web
 */
class ExplainActivity : AbsActivity() {

    //getMetaDataString("SERVER_HOST_JAVA")
    override fun getLayoutId(): Int {
        return R.layout.activity_explain
    }

    companion object {
        val EXPLAIN = "explain"
        val DESCRIPTION_OF_REIKI_INDEX = getMetaDataString("SERVER_HTML")+"/static/explain/lingqizhishu.html"//灵气指数
        val AURA_VALUE = getMetaDataString("SERVER_HTML")+"/static/explain/lingqizhi.html"//活跃度
        val MARKET_DESCRIPTION = getMetaDataString("SERVER_HTML")+"/static/explain/jishi.html"//集市说明
        val CRYSTAL_DESCRIPTION = getMetaDataString("SERVER_HTML")+"/static/explain/kuangshi.html"//能量描述
        val RULE_DESCRIPTION = getMetaDataString("SERVER_HTML")+"/static/explain/wodeguyong.html"//规则说明
        val CONTRIBUTE_DESCRIPTION = getMetaDataString("SERVER_HTML")+"/static/explain/gongxian.html"//贡献
        fun forward(context: Context, item: String) {
            val intent = Intent(context, ExplainActivity::class.java)
            intent.putExtra(EXPLAIN, item)
            context.startActivity(intent)
        }
    }

    override fun main() {
        super.main()
        im_back.setOnClickListener {
            finish()
        }
        web_view.settings.cacheMode = WebSettings.LOAD_NO_CACHE
        web_view.setBackgroundColor(0)
        if (null != intent.extras && null != intent.extras.getString(EXPLAIN)) {

            when (intent.extras.getString(EXPLAIN)) {
                DESCRIPTION_OF_REIKI_INDEX -> {
//                    im_title.text = "探索指数说明"
                    web_view.loadUrl(DESCRIPTION_OF_REIKI_INDEX)
                }
                AURA_VALUE -> {
//                    im_title.text = "探索值说明"
                    im_title.setImageResource(R.mipmap.ic_qus_reiki_top)
//                    im_title.setBackgroundResource(R.mipmap.ic_qus_reiki_top)
                    web_view.loadUrl(AURA_VALUE)
                }
                MARKET_DESCRIPTION -> {
//                    im_title.text = "集市说明"
                    web_view.loadUrl(MARKET_DESCRIPTION)
                }
                CRYSTAL_DESCRIPTION -> {
//                    im_title.text = "星矿说明"
                    im_title.setImageResource(R.mipmap.ic_qus_ml_top)
//                    im_title.setBackgroundResource(R.mipmap.ic_qus_ml_top)
                    web_view.loadUrl(CRYSTAL_DESCRIPTION)
                }
                CONTRIBUTE_DESCRIPTION -> {
//                    im_title.text = "贡献值说明"
                    im_title.setImageResource(R.mipmap.ic_qus_gxz_top)
//                    im_title.setBackgroundResource(R.mipmap.ic_qus_gxz_top)
                    web_view.loadUrl(CONTRIBUTE_DESCRIPTION)
                }
                RULE_DESCRIPTION -> {
//                    im_title.text = "规则说明"
                    web_view.loadUrl(RULE_DESCRIPTION)
                }


            }
        }


    }



    override fun onDestroy() {
        try {
            if (web_view != null) {
                web_view.destroy()
            }
        } catch (e: Exception) {
        }

        super.onDestroy()
    }
}